package com.muqi.app.network.http;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import u.aly.da;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.muqi.app.pj.shops.FictitiousShopInfo;
import com.muqi.app.pj.shops.GoodsInfo;
import com.muqi.app.pj.shops.OrderBean;
import com.muqi.app.pj.shops.OrderDetailBean;
import com.muqi.app.pj.shops.OrderIdInfo;
import com.muqi.app.pj.shops.ShopBannerBean;
import com.muqi.app.pj.shops.ShopDetialBean;
import com.muqi.app.project.application.ActivitiesStack;
import com.muqi.app.project.utils.ShowToast;
import com.muqi.app.qlearn.login.LoginActivity;
import com.muqi.app.qlearn.modles.AddressBean;
import com.muqi.app.qlearn.modles.AvatarInfo;
import com.muqi.app.qlearn.modles.Body;
import com.muqi.app.qlearn.modles.ChildInfo;
import com.muqi.app.qlearn.modles.CommentBean;
import com.muqi.app.qlearn.modles.CompanyStatisticsInfo;
import com.muqi.app.qlearn.modles.CreditInfo;
import com.muqi.app.qlearn.modles.Examination;
import com.muqi.app.qlearn.modles.GrowRewardAndMoveInfo;
import com.muqi.app.qlearn.modles.GrowTreeInfo;
import com.muqi.app.qlearn.modles.HomeBanner;
import com.muqi.app.qlearn.modles.HomeWorkBean;
import com.muqi.app.qlearn.modles.HomeWorkStatisticsInfo;
import com.muqi.app.qlearn.modles.LastRecord;
import com.muqi.app.qlearn.modles.MediaInfo;
import com.muqi.app.qlearn.modles.NoticeBean;
import com.muqi.app.qlearn.modles.PayTypeInfo;
import com.muqi.app.qlearn.modles.PersonBean;
import com.muqi.app.qlearn.modles.RecordDetailBean;
import com.muqi.app.qlearn.modles.Resolve;
import com.muqi.app.qlearn.modles.StatisticsInfo;
import com.muqi.app.qlearn.modles.StatisticsListInfo;
import com.muqi.app.qlearn.modles.StudyInfo;
import com.muqi.app.qlearn.modles.TreeHomeBean;
import com.muqi.app.qlearn.modles.TreeInfo;
import com.muqi.app.qlearn.modles.UClassInfo;
import com.muqi.app.qlearn.modles.UserInfo;
import com.muqi.app.qlearn.modles.UserMobile;
import com.muqi.app.qlearn.modles.VedioCategory;
import com.muqi.app.qlearn.modles.VedioInfo;
import com.muqi.app.user.db.MyClassBean;
import com.muqi.app.user.db.MyClassStudent;

public class ResponseUtils {

	@SuppressWarnings("unused")
	public static boolean isJsonObj(String strJson) {
		try {
			JSONObject getObj = new JSONObject(strJson.toString());
			if (getObj != null) {
				return true;
			} else {
				return false;
			}
		} catch (Exception e) {
			return false;
		}
	}

	public static JSONObject isResponseErr(Context context, String resultJson) {
		try {
			JSONObject resultAllata = null;
			resultAllata = new JSONObject(resultJson.toString());
			int errcode = resultAllata.getInt("errcode");
			String errdesc = resultAllata.getString("errdesc");
			if (errcode == 0) {
				return resultAllata;
			} else if (errcode == 90000) {
				ShowToast.showShort(context, errdesc);
				Intent intent = new Intent();
				intent.setClass(context, LoginActivity.class);
				context.startActivity(intent);
				ActivitiesStack.getInstance().popAll(true);
			} else {
				ShowToast.showShort(context, errdesc);
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		return null;
	}

	/**
	 * 判断对api操作是否成功
	 * 
	 * @param context
	 * @param resultJson
	 * @return
	 */
	public static boolean isOperationErr(Context context, String resultJson) {
		try {
			JSONObject resultAllata = null;
			resultAllata = new JSONObject(resultJson.toString());
			int errcode = resultAllata.getInt("errcode");
			String errdesc = resultAllata.getString("errdesc");
			if (errcode == 90000) {
				ShowToast.showShort(context, errdesc);
				Intent intent = new Intent();
				intent.setClass(context, LoginActivity.class);
				context.startActivity(intent);
				ActivitiesStack.getInstance().popAll(true);
				return false;
			} else if (errcode == 0) {
				return true;
			} else {
				ShowToast.showShort(context, errdesc);
				return false;
			}
		} catch (Exception e) {

		}
		return false;
	}

	public static List<HomeWorkBean> getMyHomeworkLists(Context context,
			String resultJson) {
		List<HomeWorkBean> jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				jsonData = new ArrayList<HomeWorkBean>();
				JSONArray jsonArray = resultAllata.getJSONArray("data");
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject object = jsonArray.optJSONObject(i);
					HomeWorkBean item = HomeWorkBean.fromJson(object);
					jsonData.add(item);
				}
			}
		} catch (Exception e) {
			jsonData = null;
		}
		return jsonData;
	}

	public static HomeWorkBean getHomeworkDetails(Context context,
			String resultJson) {
		HomeWorkBean jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				JSONObject dataJSON = resultAllata.getJSONObject("data");
				jsonData = HomeWorkBean.fromJson(dataJSON);
				JSONObject obj = dataJSON
						.getJSONObject("classJobConFirmStatus");
				if (jsonData != null && obj != null) {
					jsonData.setConfirmState(obj.getString("is_confirm"));
					jsonData.setWithState(obj
							.getString("parents_student_confirm"));
				}
			}
		} catch (Exception e) {
			Toast.makeText(context, "数据解析失败", Toast.LENGTH_SHORT).show();
			jsonData = null;
		}
		return jsonData;
	}

	public static List<CommentBean> getUserComments(Context context,
			String resultJson) {
		List<CommentBean> jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				jsonData = new ArrayList<CommentBean>();
				JSONArray jsonArray = resultAllata.getJSONArray("data");
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject object = jsonArray.optJSONObject(i);
					CommentBean item = CommentBean.fromJson(object);
					jsonData.add(item);
				}
			}
		} catch (Exception e) {
			jsonData = null;
		}
		return jsonData;
	}

	public static List<NoticeBean> getMyNoticeLists(Context context,
			String resultJson) {
		List<NoticeBean> jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				jsonData = new ArrayList<NoticeBean>();
				JSONArray jsonArray = resultAllata.getJSONArray("data");
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject object = jsonArray.optJSONObject(i);
					NoticeBean item = NoticeBean.fromJson(object);
					jsonData.add(item);
				}
			}
		} catch (Exception e) {
			jsonData = null;
		}
		return jsonData;
	}

	public static NoticeBean getNoticeDetails(Context context, String resultJson) {
		NoticeBean jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				JSONObject dataJSON = resultAllata.getJSONObject("data");
				jsonData = NoticeBean.fromJson(dataJSON);
				JSONObject obj = dataJSON.getJSONObject("ConFirmStatus");
				if (obj != null) {
					jsonData.read_st = obj.getString("read_st");
				}
			}
		} catch (Exception e) {
			jsonData = null;
		}
		return jsonData;
	}

	/**
	 * 
	 * @param context
	 * @param resultJson
	 * @param treeType
	 *            1-class;2-student
	 * @return
	 */
	public static GrowTreeInfo getFileTreeLists(Context context,
			String resultJson, int treeType) {
		GrowTreeInfo jsonData = new GrowTreeInfo();
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				JSONObject dataJSON = resultAllata.getJSONObject("data");
				if (treeType == 1) {
					JSONObject classJson = dataJSON.getJSONObject("classInfo");
					MyClassBean cBean = new MyClassBean();
					cBean.class_id = classJson.getString("id");
					cBean.class_name = classJson.getString("name");
					MediaInfo avatarInfo = MediaInfo.fromJson(classJson
							.getJSONObject("fileurl"));
					cBean.class_avatr = avatarInfo.fileurl_02;
					jsonData.classInfo = cBean;
				} else {
					PersonBean student = PersonBean.fromJson(dataJSON
							.getJSONObject("studentInfo"));
					if (student != null)
						jsonData.studentInfo = student;
				}

				ArrayList<TreeInfo> myTreeDetail = new ArrayList<TreeInfo>();
				JSONArray detailJSON = dataJSON.getJSONArray("detail");
				for (int i = 0; i < detailJSON.length(); i++) {
					JSONObject object = detailJSON.optJSONObject(i);
					TreeInfo tree = null;
					tree = new TreeInfo();
					tree.setId(object.getString("id"));
					tree.setFname(object.getString("fname"));
					tree.setScore(object.getString("score"));
					tree.setCreate_time(object.getString("create_time"));
					tree.setIs_open(object.getString("is_open"));
					tree.setOpen_start_date(object.getString("open_start_date"));
					tree.setOpen_end_date(object.getString("open_end_date"));
					JSONObject picJSON = object.getJSONObject("picInfo");
					if (isJsonObj(picJSON.getString("pic"))) {
						MediaInfo media = MediaInfo.fromJson(picJSON
								.getJSONObject("pic"));
						tree.picInfo = media;
					}
					myTreeDetail.add(tree);
				}
				jsonData.setDetail(myTreeDetail);
			}
		} catch (Exception e) {
			jsonData = null;
		}
		return jsonData;
	}

	public static RecordDetailBean getRecordDetails(Context context,
			String resultJson) {
		RecordDetailBean jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				JSONObject dataJSON = resultAllata.getJSONObject("data");
				jsonData = RecordDetailBean.fromJson(dataJSON);
			}
		} catch (Exception e) {
			jsonData = null;
		}
		return jsonData;
	}

	public static ArrayList<StatisticsInfo> getStatisticsInfos(Context context,
			String resultJson) {
		ArrayList<StatisticsInfo> infos = null;
		try {
			JSONObject obj = new JSONObject(resultJson);
			JSONArray dataArray = obj.getJSONArray("data");
			if (dataArray != null && dataArray.get(1) != null) {
				JSONArray array = dataArray.getJSONArray(1);
				Gson gson = new Gson();
				infos = gson.fromJson(array.toString(),
						new TypeToken<ArrayList<StatisticsInfo>>() {
						}.getType());
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return infos;

	}

	public static ArrayList<StatisticsListInfo> getStatisticsListInfos(
			Context context, String resultJson) {
		ArrayList<StatisticsListInfo> infos = null;
		try {
			JSONObject obj = new JSONObject(resultJson);
			JSONArray dataArray = obj.getJSONArray("data");
			if (dataArray != null) {
				Gson gson = new Gson();
				infos = gson.fromJson(dataArray.toString(),
						new TypeToken<ArrayList<StatisticsListInfo>>() {
						}.getType());
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return infos;
	}

	public static List<MyClassStudent> getClassMembers(Context context,
			String resultJson, String classId, String className) {
		List<MyClassStudent> jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				jsonData = new ArrayList<MyClassStudent>();
				JSONObject dataJOSN = resultAllata.getJSONObject("data");
				JSONArray jsonArray = dataJOSN.getJSONArray("unactivated");
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject object = jsonArray.optJSONObject(i);
					MyClassStudent item = null;
					item = new MyClassStudent();
					item.class_id = classId;
					item.class_name = className;

					item.student_id = object.getString("id");
					item.student_id_code = object.getString("id_code");
					item.student_name = object.getString("name");
					item.student_nick = object.getString("nickname");
					item.student_im_user_id = object.getString("im_user_id");
					item.student_mobile = object.getString("mobile");
					JSONObject avatarObject = object
							.getJSONObject("avatarInfo");
					AvatarInfo avtarInfo = AvatarInfo.fromJson(avatarObject);
					item.student_avatar = avtarInfo.fileurl_02;
					item.isActivate = false;
					jsonData.add(item);
				}
				JSONArray mJSONArray = dataJOSN.getJSONArray("activated");
				for (int i = 0; i < mJSONArray.length(); i++) {
					JSONObject object = mJSONArray.optJSONObject(i);
					MyClassStudent item = null;
					item = new MyClassStudent();
					item.class_id = classId;
					item.class_name = className;

					item.student_id = object.getString("id");
					item.student_id_code = object.getString("id_code");
					item.student_name = object.getString("name");
					item.student_nick = object.getString("nickname");
					item.student_im_user_id = object.getString("im_user_id");
					item.student_mobile = object.getString("mobile");
					JSONObject avatarObject = object
							.getJSONObject("avatarInfo");
					AvatarInfo avtarInfo = AvatarInfo.fromJson(avatarObject);
					item.student_avatar = avtarInfo.fileurl_02;
					item.isActivate = false;
					jsonData.add(item);
				}
			}
		} catch (Exception e) {
			jsonData = null;
		}
		return jsonData;
	}

	public static ArrayList<HomeWorkStatisticsInfo> getHomeStatisticsInfos(
			Context context, String resultJson) {
		ArrayList<HomeWorkStatisticsInfo> infos = null;

		try {
			JSONObject obj = new JSONObject(resultJson);
			JSONObject dataObj = obj.getJSONObject("data");
			JSONArray dataArray = dataObj.getJSONArray("detail");
			if (dataArray != null) {
				Gson gson = new Gson();
				infos = gson.fromJson(dataArray.toString(),
						new TypeToken<ArrayList<HomeWorkStatisticsInfo>>() {
						}.getType());
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return infos;
	}

	public static ArrayList<CompanyStatisticsInfo> getCompanyStatisticsInfos(
			Context context, String resultJson) {
		ArrayList<CompanyStatisticsInfo> infos = null;

		try {
			JSONObject obj = new JSONObject(resultJson);
			JSONObject dataObj = obj.getJSONObject("data");
			JSONArray dataArray = dataObj.getJSONArray("detail");
			if (dataArray != null) {
				Gson gson = new Gson();
				infos = gson.fromJson(dataArray.toString(),
						new TypeToken<ArrayList<CompanyStatisticsInfo>>() {
						}.getType());
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return infos;
	}

	public static List<ChildInfo> getMyChildren(Context context,
			String resultJson) {
		List<ChildInfo> jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				jsonData = new ArrayList<ChildInfo>();
				JSONArray jsonArray = resultAllata.getJSONArray("data");
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject object = jsonArray.optJSONObject(i);
					ChildInfo item = ChildInfo.fromJson(object);
					jsonData.add(item);
				}
			}
		} catch (Exception e) {
			Toast.makeText(context, "数据解析失败", Toast.LENGTH_SHORT).show();
			jsonData = null;
		}
		return jsonData;
	}

	public static UClassInfo getMyChildClassInfo(Context context,
			String resultJson) {
		UClassInfo jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				JSONObject dataJSON = resultAllata.getJSONObject("data");
				jsonData = UClassInfo.fromJson(dataJSON);
			}
		} catch (Exception e) {
			jsonData = null;
		}
		return jsonData;
	}

	public static TreeHomeBean getTreeHomeDatas(Context context,
			String resultJson) {
		TreeHomeBean jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				JSONObject dataJSON = resultAllata.getJSONObject("data");
				jsonData = TreeHomeBean.fromJson(dataJSON);
			}
		} catch (Exception e) {
			jsonData = null;
		}
		return jsonData;
	}

	public static ArrayList<GrowRewardAndMoveInfo> getGrowStatisticsInfos(
			Context context, String resultJson) {
		ArrayList<GrowRewardAndMoveInfo> infos = new ArrayList<GrowRewardAndMoveInfo>();

		try {
			JSONObject obj = new JSONObject(resultJson);
			JSONArray dataArray = obj.getJSONArray("data");

			if (dataArray != null) {
				Gson gson = new Gson();
				infos = gson.fromJson(dataArray.toString(),
						new TypeToken<ArrayList<GrowRewardAndMoveInfo>>() {
						}.getType());
			}
		} catch (JSONException e) {
			e.printStackTrace();
			// Log.e("===", infos.size()+"  dfg"+e.getMessage());
		}
		return infos;
	}

	public static ArrayList<RecordDetailBean> getRecordListDetails(
			Context context, String resultJson) {
		ArrayList<RecordDetailBean> arrayList = null;

		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				JSONArray dataJSON = resultAllata.getJSONArray("data");
				Gson gson = new Gson();
				arrayList = gson.fromJson(dataJSON.toString(),
						new TypeToken<ArrayList<RecordDetailBean>>() {
						}.getType());

			}
		} catch (JSONException e) {
			arrayList = null;
		}
		return arrayList;
	}

	public static ArrayList<ArrayList<PayTypeInfo>> getPayTypeLists(
			Context context, String result) {
		ArrayList<ArrayList<PayTypeInfo>> infos = new ArrayList<ArrayList<PayTypeInfo>>();
		ArrayList<PayTypeInfo> info;
		try {
			JSONObject resultAllata = new JSONObject(result);
			if (resultAllata != null) {
				JSONObject dataObj = resultAllata.getJSONObject("data");
				if (dataObj != null) {
					Gson gson = new Gson();
					JSONArray baseArray = dataObj.getJSONArray("base");
					if (baseArray != null) {
						info = gson.fromJson(baseArray.toString(),
								new TypeToken<ArrayList<PayTypeInfo>>() {
								}.getType());
						infos.add(info);
					}

					JSONArray flowerArray = dataObj.getJSONArray("flower");
					if (flowerArray != null) {
						info = gson.fromJson(flowerArray.toString(),
								new TypeToken<ArrayList<PayTypeInfo>>() {
								}.getType());
						infos.add(info);
					}

				}

			}
		} catch (JSONException e) {
			infos = null;
		}

		return infos;
	}

	public static PersonBean getUserBaseInfos(Context context, String resultJson) {
		PersonBean jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				JSONObject dataJSON = resultAllata.getJSONObject("data");
				jsonData = PersonBean.fromJson(dataJSON);
			}
		} catch (Exception e) {
			jsonData = null;
		}
		return jsonData;
	}

	public static List<ShopBannerBean> getShopGoods(Context context,
			String resultJson) {
		List<ShopBannerBean> jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				jsonData = new ArrayList<ShopBannerBean>();
				JSONArray jsonArray = resultAllata.getJSONArray("data");
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject object = jsonArray.optJSONObject(i);
					ShopBannerBean item = ShopBannerBean.fromJson(object);
					jsonData.add(item);
				}
			}
		} catch (Exception e) {
			jsonData = null;
		}
		return jsonData;
	}

	public static ShopDetialBean getShopGoodsDetial(Context context,
			String resultJson) {
		ShopDetialBean jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {

				JSONObject jsonArray = resultAllata.getJSONObject("data");
				jsonData = ShopDetialBean.fromJson(jsonArray);
			}
		} catch (Exception e) {
			jsonData = null;
		}
		return jsonData;
	}

	public static FictitiousShopInfo getXuniGoodsDetial(Context context,
			String resultJson) {
		FictitiousShopInfo jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {

				JSONObject jsonArray = resultAllata.getJSONObject("data");
				Gson gson = new Gson();
				jsonData = gson.fromJson(jsonArray.toString(),
						FictitiousShopInfo.class);
			}
		} catch (Exception e) {
			jsonData = null;
		}
		return jsonData;
	}

	public static ArrayList<CreditInfo> getCreditInfoList(Context context,
			String resultJson) {
		ArrayList<CreditInfo> arrayList = null;

		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				JSONArray dataJSON = resultAllata.getJSONArray("data");
				Gson gson = new Gson();
				arrayList = gson.fromJson(dataJSON.toString(),
						new TypeToken<ArrayList<CreditInfo>>() {
						}.getType());

			}
		} catch (JSONException e) {
			arrayList = null;
		}
		return arrayList;
	}

	public static List<AddressBean> getAddressList(Context context,
			String result) {
		List<AddressBean> jsonData = null;
		JSONObject resultAllata = null;
		resultAllata = isResponseErr(context, result);
		if (resultAllata != null) {
			try {
				jsonData = new ArrayList<AddressBean>();
				AddressBean item = null;
				JSONArray jsonArray = resultAllata.getJSONArray("data");
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject object = jsonArray.optJSONObject(i);
					item = new AddressBean();
					item.setDizhi_id(object.getString("dizhi_id"));
					item.setDizhi(object.getString("dizhi"));
					item.setLianxidianhua(object.getString("lianxidianhua"));
					item.setChangyong(object.getString("changyong"));
					item.setLianxiren(object.getString("lianxiren"));
					item.setProvince_name(object.getString("province_name"));
					item.setCity_name(object.getString("city_name"));
					item.setDistrict_name(object.getString("district_name"));
					item.setProvince_id(object.getString("province_id"));
					item.setCity_id(object.getString("city_id"));
					item.setDistrict_id(object.getString("district_id"));
					jsonData.add(item);
				}
			} catch (Exception e) {

			}
		}
		return jsonData;
	}

	public static ArrayList<PersonBean> getLikeList(Context context,
			String resultJson) {
		ArrayList<PersonBean> arrayList = null;
		PersonBean bean = null;

		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				JSONArray dataJSON = resultAllata.getJSONArray("data");
				arrayList = new ArrayList<PersonBean>();
				for (int i = 0; i < dataJSON.length(); i++) {
					JSONObject obj = dataJSON.getJSONObject(i);
					JSONObject userObj = obj.getJSONObject("userinfo");
					bean = PersonBean.fromJson(userObj);
					arrayList.add(bean);
				}

			}
		} catch (JSONException e) {

			arrayList = null;
		}
		return arrayList;
	}

	public static ArrayList<PersonBean> getFollowList(Context context,
			String resultJson) {
		ArrayList<PersonBean> arrayList = null;
		PersonBean bean = null;

		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				JSONArray dataJSON = resultAllata.getJSONArray("data");
				arrayList = new ArrayList<PersonBean>();
				for (int i = 0; i < dataJSON.length(); i++) {
					JSONObject obj = dataJSON.getJSONObject(i);
					JSONObject userObj = obj.getJSONObject("userInfo");
					bean = PersonBean.fromJson(userObj);
					arrayList.add(bean);
				}

			}
		} catch (JSONException e) {

			arrayList = null;
		}
		return arrayList;
	}

	public static OrderIdInfo getOrderId(Context context, String resultJson) {
		OrderIdInfo orderId = null;

		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			JSONObject obj = resultAllata.getJSONObject("data");
			Gson gson = new Gson();
			orderId = gson.fromJson(obj.toString(), OrderIdInfo.class);
		} catch (JSONException e) {
			orderId = null;
		}
		return orderId;
	}

	public static ArrayList<OrderBean> getOrderList(Context context,
			String result) {
		ArrayList<OrderBean> orderData = null;
		JSONObject resultAllata = null;
		resultAllata = ResponseUtils.isResponseErr(context, result);
		if (resultAllata != null) {
			try {
				orderData = new ArrayList<OrderBean>();
				JSONArray jsonArray = resultAllata.getJSONArray("data");
				for (int i = 0; i < jsonArray.length(); i++) {
					OrderBean orderItem = null;
					orderItem = new OrderBean();

					JSONObject object = jsonArray.optJSONObject(i);
					orderItem.setDingdan_id(object.getInt("dingdan_id"));
					orderItem.setDingdanhao(object.getString("dingdanhao"));
					orderItem.setUser_id(object.getInt("user_id"));
					orderItem.setZongjia(object.getDouble("zongjia"));
					orderItem.setYunfei(object.getDouble("yunfei"));
					orderItem.setZongji(object.getDouble("zongji"));
					orderItem.setZhifulaiyuan(object.getString("zhifulaiyuan"));
					orderItem.setCreatetime(object.getString("createtime"));
					orderItem.setLiuyan(object.getString("liuyan"));
					orderItem.setEndtime(object.getString("endtime"));
					orderItem.setZhuangtai(object.getString("zhuangtai"));
					orderItem.setObj_type(object.getString("obj_type"));

					List<OrderDetailBean> orderDetail = new ArrayList<OrderDetailBean>();
					JSONArray detailArray = object.getJSONArray("dingdan_mx");
					for (int j = 0; j < detailArray.length(); j++) {
						JSONObject detailObject = detailArray.optJSONObject(j);
						OrderDetailBean detailItem = null;
						detailItem = new OrderDetailBean();
						detailItem.setMingxi_id(detailObject
								.getInt("mingxi_id"));
						detailItem.setDingdan_id(detailObject
								.getInt("dingdan_id"));
						detailItem.setShangpin_id(detailObject
								.getInt("shangpin_id"));
						detailItem.setDanjia(detailObject.getDouble("danjia"));
						detailItem.setShuliang(detailObject.getInt("shuliang"));
						detailItem.setHeji(detailObject.getDouble("heji"));
						detailItem.setMingxi_zhangtai(detailObject
								.getString("mingxi_zhangtai"));
						detailItem.setTuihuo_zhuangtai(detailObject
								.getString("tuihuo_zhuangtai"));

						GoodsInfo goodsInfo = new GoodsInfo();
						JSONObject goodsObject = detailObject
								.getJSONObject("shangpin_xq");

						goodsInfo.shangpin_id = goodsObject
								.getString("shangpin_id");
						goodsInfo.mingcheng = goodsObject
								.getString("mingcheng");
						goodsInfo.fenlei = goodsObject.getString("fenlei");
						goodsInfo.fileurl = MediaInfo.fromJson(goodsObject
								.getJSONObject("fileurl"));
						goodsInfo.danjia = (float) goodsObject
								.getDouble("danjia");
						goodsInfo.kucun = goodsObject.getInt("kucun");
						goodsInfo.yunfei = (float) goodsObject
								.getDouble("yunfei");
						goodsInfo.zhuangtai = goodsObject
								.getString("zhuangtai");
						goodsInfo.obj_type = goodsObject.getString("obj_type");
						goodsInfo.zhichituihuo = goodsObject
								.getString("zhichituihuo");

						detailItem.setShangpin_xq(goodsInfo);

						orderDetail.add(detailItem);
					}
					orderItem.setDingdan_mx(orderDetail);
					orderData.add(orderItem);
				}
			} catch (Exception e) {
			}
		}
		return orderData;
	}

	public static ArrayList<OrderBean> getXuniOrderList(Context context,
			String result) {
		ArrayList<OrderBean> orderData = null;
		JSONObject resultAllata = null;
		resultAllata = ResponseUtils.isResponseErr(context, result);
		if (resultAllata != null) {
			try {
				orderData = new ArrayList<OrderBean>();
				JSONArray jsonArray = resultAllata.getJSONArray("data");
				Gson gson = new Gson();
				orderData = gson.fromJson(jsonArray.toString(),
						new TypeToken<ArrayList<OrderBean>>() {
						}.getType());

			} catch (Exception e) {
			}
		}
		return orderData;
	}

	public static List<FictitiousShopInfo> getFictitiousShopInfo(
			Context context, String resultJson) {
		List<FictitiousShopInfo> arrayList = null;

		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				JSONArray dataJSON = resultAllata.getJSONArray("data");
				Gson gson = new Gson();
				arrayList = gson.fromJson(dataJSON.toString(),
						new TypeToken<List<FictitiousShopInfo>>() {
						}.getType());

			}
		} catch (JSONException e) {
			arrayList = null;
		}
		return arrayList;
	}

	public static UserInfo getUserInfo(Context context, String resultJson) {
		UserInfo info = null;

		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				JSONObject dataJSON = resultAllata.getJSONObject("data");
				info = UserInfo.fromJson(dataJSON);

			}
		} catch (JSONException e) {
			info = null;
		}
		return info;
	}

	public static List<HomeBanner> getHomeBanners(Context context,
			String resultJson) {
		List<HomeBanner> jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				jsonData = new ArrayList<HomeBanner>();
				JSONArray jsonArray = resultAllata.getJSONArray("data");
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject object = jsonArray.optJSONObject(i);
					HomeBanner item = HomeBanner.fromJson(object);
					jsonData.add(item);
				}
			}
		} catch (Exception e) {
			jsonData = null;
		}
		return jsonData;
	}

	public static UserMobile getUserMobile(Context context, String resultJson) {
		UserMobile jsonData = null;
		try {
			JSONObject resultAllata = new JSONObject(resultJson);
			if (resultAllata != null) {
				JSONObject obj = resultAllata.getJSONObject("data");
				jsonData = UserMobile.fromJson(obj);
			}
		} catch (Exception e) {
			jsonData = null;
		}
		return jsonData;
	}

	public static List<VedioCategory> getVedioCategories(Context context,
			String resultJson) {
		List<VedioCategory> jsonData = null;
		Gson gson = new Gson();
		jsonData = gson.fromJson(resultJson,
				new TypeToken<ArrayList<VedioCategory>>() {
				}.getType());
		return jsonData;
	}

	public static List<VedioInfo> getVedioInfos(Context context,
			String resultJson) {
		List<VedioInfo> jsonData = null;
		Gson gson = new Gson();
		jsonData = gson.fromJson(resultJson,
				new TypeToken<ArrayList<VedioInfo>>() {
				}.getType());
		return jsonData;
	}

	public static Body getBody(Context context, String resultJson) {
		Body jsonData = null;
		try {
			JSONObject obj = new JSONObject(resultJson);
			JSONObject objData = obj.getJSONObject("data");
			Gson gson = new Gson();
			jsonData = gson.fromJson(objData.toString(), Body.class);

		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			jsonData = null;
		}
		return jsonData;
	}
	public static LastRecord getLastTreeinfo(Context context, String resultJson) {
		LastRecord jsonData = null;
		try {
			JSONObject obj = new JSONObject(resultJson);
			JSONObject objData = obj.getJSONObject("data");
			if(objData!=null){
				Gson gson = new Gson();
				jsonData = gson.fromJson(objData.toString(), LastRecord.class);
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			jsonData = null;
		}
		return jsonData;
	}
	
	public static ArrayList<StudyInfo> getStudyInfos(
			Context context, String resultJson) {
		ArrayList<StudyInfo> infos = null;

		try {
			JSONObject obj = new JSONObject(resultJson);
			JSONArray dataArray = obj.getJSONArray("data");

			if (dataArray != null) {
				Gson gson = new Gson();
				infos = gson.fromJson(dataArray.toString(),
						new TypeToken<ArrayList<StudyInfo>>() {
						}.getType());
			}
		} catch (JSONException e) {
			e.printStackTrace();
			infos=null;
		}
		return infos;
	}
	public static ArrayList<Examination> getExaminationInfos(
			Context context, String resultJson) {
		ArrayList<Examination> infos = null;

		try {
			JSONObject obj = new JSONObject(resultJson);
			JSONArray dataArray = obj.getJSONArray("data");

			if (dataArray != null) {
				Gson gson = new Gson();
				infos = gson.fromJson(dataArray.toString(),
						new TypeToken<ArrayList<Examination>>() {
						}.getType());
			}
		} catch (JSONException e) {
			e.printStackTrace();
			infos=null;
		}
		return infos;
	}
	public static ArrayList<Resolve> getResolveInfos(
			Context context, String resultJson) {
		ArrayList<Resolve> infos = null;

		try {
			JSONObject obj = new JSONObject(resultJson);
			JSONArray dataArray = obj.getJSONArray("data");

			if (dataArray != null) {
				Gson gson = new Gson();
				infos = gson.fromJson(dataArray.toString(),
						new TypeToken<ArrayList<Resolve>>() {
						}.getType());
			}
		} catch (JSONException e) {
			e.printStackTrace();
			infos=null;
		}
		return infos;
	}
	public static Examination getExaminationInfo(
			Context context, String resultJson) {
		Examination info = null;

		try {
			JSONObject obj = new JSONObject(resultJson);
			JSONObject objData = obj.getJSONObject("data");
			if(objData!=null){
				Gson gson = new Gson();
				info = gson.fromJson(objData.toString(), Examination.class);
			}
		} catch (JSONException e) {
			e.printStackTrace();
			info=null;
		}
		return info;
	}
}
